package com.ice.app.system.log.listener;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.stereotype.Component;

import com.iceframework.core.utils.JsonUtils;

@Component("logListener")
public class LogListener {

	private static final Logger log = LoggerFactory.getLogger(LogListener.class);

	@Autowired
	JmsTemplate jmsTemplate;

	@JmsListener(destination = "Login_Log", concurrency = "5-10")
	public void onMessageGetMsg(Message message, Session session) throws JMSException {
		try {
			String obj = JsonUtils.convertObj2String(jmsTemplate.getMessageConverter().fromMessage(message));
			log.info("MSG--信道接收一条消息" + JsonUtils.convertString2Obj(obj, String.class));
			message.acknowledge();
			message.acknowledge();
		} catch (MessageConversionException | JMSException e) {
			e.printStackTrace();
		}

	}

}
